import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ValueListenableBuilerDemo(),
    );
  }
}

class ValueListenableBuilerDemo extends StatefulWidget {
  @override
  _ValueListenableBuilerDemoState createState() =>
      _ValueListenableBuilerDemoState();
}

class _ValueListenableBuilerDemoState extends State<ValueListenableBuilerDemo> {
  ValueNotifier _valueNotifier = ValueNotifier<int>(0);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ValueListenableBuilder(
          valueListenable: _valueNotifier,
          builder: (context, value, child) {
            return Text(
              "改变后 值=$value",
              style: TextStyle(
                  decoration: TextDecoration.none,
                  color: Colors.white,
                  fontSize: 14),
            );
          },
        ),
        Padding(
          padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
          child: ElevatedButton(
              onPressed: () {
                _valueNotifier.value++;
              },
              child: Text("点我看看")),
        )
      ],
    );
  }
}
